package com.iscreen.downloader;

import java.util.Map.Entry;

import com.iscreen.downloader.settings.DownloaderSettings;
import com.iscreen.utils.constants.Constants;
import com.iscreen.utils.download.FileDownloader;
import com.iscreen.utils.exceptions.IScreenException;

public class StocksStructuresDownloader {

	private static StocksStructuresDownloader downloader = new StocksStructuresDownloader();

	public void run()
	{
		try
		{
			String baseStructuresURL = DownloaderSettings.getInstance().getBaseStructuresURL();
			String targetPath = DownloaderSettings.getInstance().getDownloadTargetPath();

			for (Entry<String, String> downloadMapping : DownloaderSettings.getInstance().getDownloadMappings().entrySet())
			{
				String source = baseStructuresURL + Constants.URL_SEPARATOR + downloadMapping.getValue();
				String target = targetPath + Constants.FILE_SEPARATOR + downloadMapping.getKey() + Constants.FILE_EXTENSION_SEPARATOR + Constants.FILE_EXTENSION_TXT;
				FileDownloader.download(source, target);
			}
		}
		catch (IScreenException e)
		{
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		downloader.run();
		System.exit(0);
	}

}
